/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef USIHardwareTest_H_
#define USIHardwareTest_H_

#include "TestCase.h"
#include "Coms/USI/USIHardware.h"
#include <stdio.h>
#include <math.h>

using Coms::USI::USIHardware;

#define READ_MARGIN 10

class USIHardwareTest : public TestCase<USIHardwareTest>
{
public:

	USIHardwareTest(const prog_mem * testMethodName_P, TestCase<USIHardwareTest>::TestMethod testMethod) :
	TestCase<USIHardwareTest>(testMethodName_P, testMethod)
	{

		usiHardware = USIHardware::getUSIHardware();

	}

	void setUp()
	{
	}

	void tearDown()
	{
		usiHardware->disable();
	}

	bool testgetUSIHardware()
	{
		return AVRUNIT_ASSERT(!isNull(usiHardware));
	}

	bool testMCP41050()
	{
//		setBit(DDRC, PINC0); //PINC0 is SS, set it as output
//		setBit(PORTC, PINC0); // pull SS high
//
//		DDRB = (1<<PINB0) | (1<<PINB1) | (1<<PINB2); // set SCK and MOSI as output
//
//		setBit(PORTB, PINB0);
//
//		usiHardware->setPrescaler(Coms::SPI::Prescalers::DIV_128, false);
//		usiHardware->setMaster();
//		usiHardware->setSCKHighWhenIdle();
//		usiHardware->sampleDataOnSCKLeadingEdge();
//		usiHardware->transmitMSBFirst();

		usiHardware->enableInSPIMode();


		uint8_t potValue = 0x00;

		while(true)
		{
//		clearBit(PORTC, PINC0); // pull SS low
//
//		usiHardware->writeByte(0x17);
//
//		while(!usiHardware->readInterruptFlag());
//
//		usiHardware->clearInterruptFlag();
//
//		usiHardware->writeByte(potValue);
//
//		while(!usiHardware->readInterruptFlag());
//
//		usiHardware->clearInterruptFlag();
//
//
//		setBit(PORTC, PINC0); // pull SS high

		potValue++;

		}



//		return result;

	}

	USIHardware * usiHardware;

};

#endif /* USIHardwareTest_H_ */
